import java.util.*;


public class RequestSource {
	private String _peerName = null;			// the peer name of the source
	private Date _existingDbVersion = null;		// the peer's DB version that the program's DB is synchronized with
	private Source _source = null;				// source communication information 
	
	/**
	 * Constructor
	 * @param source
	 */
	public RequestSource(Source source){
		_source = source;
	}
	
	/**
	 * Constructor
	 * @param peerName
	 * @param existingDbVersion
	 * @param source
	 */
	public RequestSource( String peerName, Date existingDbVersion, Source source){
		_peerName = peerName;
		_existingDbVersion = existingDbVersion;
		_source = source;
	}
	
	/**
	 * equals Function
	 */
	@Override
	public boolean equals(Object o){
		if(!(o instanceof RequestSource))
			return false;
		RequestSource req = (RequestSource) o;
		if (_source.getIP().equals(req.getSource().getIP()) && _source.getPort() == req.getSource().getPort())
			return true;
		return false;
	}
	
	/**
	 * hashCode Function
	 */
	@Override
	public int hashCode(){
		return _source.getIP().hashCode()*31 + new Integer(_source.getPort()).hashCode();
	}
	
	// get functions //
	public String getPeerName() { return _peerName; }

	public Date getExistingDbVersion() { return _existingDbVersion; }
	
	public Source getSource() { return _source; }
	
	// set functions //
	public void setSource(Source source) { _source = source; }
}
